<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
 <%@ include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>画家${painter.name }基本信息及作品集</title>
<link href="../style/css_member.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/common.js"></script>
<script src="../js/artDialog.js?skin=gray"></script>
<script src="../js/artDialog.iframeTools.js"></script>
<script type="text/javascript" src="../js/jquery-1.3.2.js"></script>
<script type="text/javascript">

/******改变作品上传状态 *****/
function changeState(id,status){
	if(status == '2'){
		if (window.confirm("确认删除此作品？")) {
			$.ajax( {
				type : "POST",
				url : "${ctx}/painting/changeUploadState.do?painting.id="+id+"&operateStr="+status,
				timeout : 6000,
				async : false, //ajax同步
				success : function(data, textStatus) {
					if(data == '0000'){
						window.location.reload(true);
					}
				}
			});
		}
	}else{
		$.ajax( {
			type : "POST",
			url : "${ctx}/painting/changeUploadState.do?painting.id="+id+"&operateStr="+status,
			timeout : 6000,
			async : false, //ajax同步
			success : function(data, textStatus) {
				if(data == '0000'){
					window.location.reload(true);
				}
			}
		});
	}
}


$(function(){
	$("#painterLink").click(function(){
		art.dialog.open('${ctx}/fileUpload!uploadPrepare.do?imgType=painter&sharpId=6',{title:'修改艺术家照片',width:800,height:550},false);
    });

    $("#addPaintingImage").click(function(){
        var type = '${painter.type}';
        if(type == '2'){
        	art.dialog.open('${ctx }/painting/addPrepareByPainterStar.do?painter_Id=${painter.id }',{title:'为艺术家添加作品',width:820,height:550,lock:true},false);
        }else{
    		art.dialog.open('${ctx }/painting/addPrepareByPainter.do?painter_Id=${painter.id }',{title:'为艺术家添加作品',width:820,height:550,lock:true},false);
        }
    });

    $("a[name='modifyHref']").click(function(){
		var id = $(this).attr("title");
		art.dialog.open('${ctx}/painting/modifyPrepare.do?painting.id='+id,{title:'修改作品',width:820,height:550,lock:true},false);
    });

	checkMarketIndex();
	
	var city_id = '${painter.cityInfo.id}';
	checkCity(city_id);

    $("#englishName").blur(function(){
    	checkEnglishName();
     });
});

function checkMarketIndex(){
	
	var time_period1  = '${painter.newIndex.time_period }';
	var time_period2  = '${painter.maxIndex.time_period }';
	var time_period3  = '${painter.minIndex.time_period }';
	var time_period4  = '${painter.newestIndex.time_period }';

	$("#time_period_1").val(time_period1);
	$("#time_period_2").val(time_period2);
	$("#time_period_3").val(time_period3);
	$("#time_period_4").val(time_period4);
}

	function checkForm(){

		var name = $.trim($("#name").val());
		if( name  ==  ""){
			$("#name").focus();
			 alert("艺术家姓名不能为空。");
			 return false;
		}

		if(!checkEnglishName()){
			return false;
		}

		var picImage = $("#picImage").val();
		if( picImage == "" ){
			alert("请上传艺术家照片");
			return false;
		}

		var age = $("#age").val();
		if(age == ""){
			$("#age").val("");
			$("#age").focus();
			alert("请输入合法的年龄");
			return false;
		}

		var achievement1 = $("#achievement1").val();
		if(achievement1 == ""){
			alert("请填写艺术家从艺历程。");
			return false;
		}
		
		var province = $("#provinceInfoSelect").val();
		var city = $("#cityInfoSelect").val();
		var address =  $.trim($("#address").val());
		if(province == "" && address == ""){
			alert("请填写名家的所在地");
			return false;
		}
		
		if(window.confirm("确认修改艺术家资料？")){
			$.ajax({
				type:'POST',
				url:'${ctx }/painter/modify.do',
				async : false, //ajax同步
				data:$("#painterForm").serialize(),//序列化表单里所有的内容
				success: function(data){
					 var arr = data.split(",");
					if(arr.length > 2 ){
						if(arr[0]=='0000'){
			    			alert("艺术家资料保存成功！");
			    			var win = art.dialog.open.origin;//来源页面
							// 如果父页面重载或者关闭其子对话框全部会关闭
							win.location.reload();
							return false;
						}
					}else{
						alert("艺术家资料保存失败！");
						return false;
					}
				}
			});
		}
	}

	/**
	* 检查汉语拼音是否重复
	*/
	function checkEnglishName(){
        var englishName = $("#englishName").val();
        if(englishName == ""){
			alert("请填写艺术家姓名的汉语拼音。");
			return false;
        }
        var painter_id = $("#painter_id").val();
        return $.ajax({
			type:'POST',
			url:'${ctx }/front/painterAction!checkEnglishName.do?englishName='+englishName+'&painter_id='+painter_id,
			async : false, //ajax同步
			success: function(data){
				var returnMsg = eval('('+data+')');
				if(returnMsg.code == '0000'){
					return true;
				}else{
					alert(returnMsg.message);
					return false;
				}
			}
		});
	}
	
	/**
	*查看该画家所有作品,进入排序列表页
	*/
	function view_paintings_painter(){
		var painter_id = $("#painter_id").val();
		location.href = "${ctx}/painting/paintingAction!listAllPaintingsOfPainter.do?painter_Id="+painter_id;
	}

</script>	
	
</head>
<body>

<!-- 页面头部  -->
<jsp:include page="/commons/head_member.jsp"></jsp:include>

<form action="${ctx }/painter/modify.do" method="post" id="painterForm" name="painterForm">
<table width="960" border="0" cellspacing="0" cellpadding="0" align="center"  class="tbl_border_top"  bgcolor="#ffffff">
                    <tr>
                      <td colspan="3"  class="bt14A" align="center">${painter.name }简介</td>
                    </tr>
                <tr>
                  <td class="bt14A" align="right"><span class="style15">*</span> 艺术家姓名：</td>
                  <td class="bt14A">
                    <input name="painter.name" type="text" size="20" id="name" value="${painter.name }">
                                                     汉语拼音：<input name="painter.englishName" type="text" size="10" id="englishName" maxlength="40" value="${painter.englishName }">
                 </td>
                  <td width="160" rowspan="10" class="bt14A" align="left" valign="top">
                        <table width="150" height="184" border="0" cellpadding="0" cellspacing="1" bordercolor="#CCCCCC" bgcolor="#CCCCCC">
                          <tr>
                            <td bgcolor="#FFFFFF">
                             	<div id="photoTd" style="width: 150px;height: 184px;vertical-align: middle;text-align: center;overflow: hidden;">
                        	 		<img src="${painter.originalImagePath }" border="0" width="147" height="181">
                        	 	</div>
                            </td>
                          </tr>
                        </table>
                  </td>
                </tr>
               <tr>
                  <td class="bt14A" align="right"></td>
                  <td class="bt14A">字<input name="painter.zi" type="text" size="6" value="${painter.zi }">
                      		号<input name="painter.hao" type="text" size="6" value="${painter.hao }">
                  </td>
                  <td></td>
              </tr>
                <c:if test="${painter.type == 1 }">
	                <tr>
	                  <td class="bt14A" align="right"><span class="style15">*</span> 选择门类：</td>
	                  <td class="bt14A">
	                       <select name="painter.catalogType.id" id="catalogTypeSelect">
			         			 <c:forEach items="${catalogTypeList}" var="catalogType" varStatus="status">
			            	 		<option value="${ catalogType.id}" <c:if test="${ painter.catalogType.id == catalogType.id }">selected</c:if>/> ${ catalogType.name}</option>
			         			 </c:forEach>
				     	  </select>	
	                  </td>
	                  <td></td>
	                </tr>
                </c:if>
                <c:if test="${painter.type == 2 }">
                 <tr>
                   <td class="bt14A" align="right"><span class="style15">*</span> 选择年代：</td>
	               <td class="bt14A" align="left">
	                  	<select name="painter.decade">
		                    <option value="1" <c:if test="${painter.decade == 1}">selected="selected"</c:if>>近现代国画名家</option>
		                    <option value="2" <c:if test="${painter.decade == 2}">selected="selected"</c:if>>近现代油画名家</option>
		                    <option value="3" <c:if test="${painter.decade == 3}">selected="selected"</c:if>>当代国画名家</option>
		                    <option value="4" <c:if test="${painter.decade == 4}">selected="selected"</c:if>>当代油画名家</option>
		                    <option value="5" <c:if test="${painter.decade == 5}">selected="selected"</c:if>>古代国画名家</option>
		                    <option value="6" <c:if test="${painter.decade == 6}">selected="selected"</c:if>>国外名家</option>
	                    </select>
                   </td>
                   <td></td>
                  </tr>
                </c:if>
                <tr>
                  <td class="bt14A" align="right"><span class="style15">*</span>艺术家照片：</td>
                  <td class="bt14A"><span class="style18"><a id="painterLink" style="cursor: pointer;color: red">上传</a></span></td>
                  <td></td>
                </tr>
                <tr>
                  <td class="bt14A" align="right"><span class="style15">*</span> 年 龄：</td>
                  <td class="bt14A" align="left">
                  <input name="painter.age" type="text" size="3" id="age" maxlength="4" value="${painter.age }">
                     	 年生                  
                  <c:if test="${painter.type == 2 }">
                  		<input name="painter.endAge" type="text" size="3" id="endAge" maxlength="4" value="${painter.endAge }">年逝
                  </c:if>
                  </td>
                  <td></td>
                </tr>
                <tr>
                  <td class="bt14A" align="right">毕业院校：</td>
                  <td class="bt14A">
                      <input name="painter.graduatedFrom" type="text" size="30" id="graduatedFrom"  value="${painter.graduatedFrom }">
                  </td>
                  <td></td>
                </tr>
                <tr>
                  <td class="bt14A" align="right">职业/头衔：</td>
                  <td class="bt14A">
                       <input name="painter.honour" type="text" size="40" id="honour"  value="${painter.honour }" maxlength="100">
                  </td>
                  <td></td>
                </tr>
             	<c:if test="${painter.type == 2 }">
	               <%@include file="/commons/painter_star_market_fragment.jsp" %>
	            </c:if>
                <tr>
                  <td class="bt14A" align="right"><span class="style15">* </span>
                  <c:if test="${painter.type == 1 }">
                  	所在地：
                   </c:if>
                  <c:if test="${painter.type == 2 }">
                  	籍贯:
                  </c:if>
                  	</td>
                  <td class="bt14A" align="left">
                     <select name="painter.provinceInfo.id" id="provinceInfoSelect" onchange="changeProvince()">
                        <option value="">选择省份</option>
                        <c:forEach items="${provinceInfoList}" var="provinceInfo" varStatus="status">
				            <option value="${ provinceInfo.id}" <c:if test="${painter.provinceInfo.id == provinceInfo.id }">selected="selected"</c:if>/> ${ provinceInfo.name}</option>
				        </c:forEach>
                    </select>
                      <select name="painter.cityInfo.id" id="cityInfoSelect">
                        <option value="">选择县市</option>
                      </select>
                     <c:if test="${painter.type == 2 }">
                     	<input name="painter.address" type="text" size="40" id="address" value="${painter.address }">
                     </c:if>
                  </td>
                  <td></td>
                </tr>
                <tr>
                  <td class="bt14A" align="right"><span class="style15">*</span> 艺术人生：</td>
                  <td class="bt14A" colspan="2">
                       <textarea rows="8" cols="80"  name="painter.description"  id="achievement1">${painter.description }</textarea>
                  </td>
                </tr>
                <tr>
                  <td width="180">
                  	<!-- 隐藏域 begin  -->
                   		<input name="painter.id" type="hidden" size="20" id="painter_id" value="${painter.id }">
                   		<input name="painter.imageInfo.id" type="hidden"  id="picImage" value="${painter.imageInfo.id }">
                   		<input name="painter.type" type="hidden"  id="painter_type" value="${painter.type }">
               		<!-- 隐藏域 end  --> 
                  </td>
                  <td class="nw12a" align="left">
                 	 <img src="../images/an24b.gif" width="106" height="31"  onClick="javascript:checkForm()" style="cursor: pointer ;border: 0"></td>
                </tr>
</table>
   
	<table width="960" border="0" cellspacing="0" cellpadding="0"  class="tbl_border"  bgcolor="#ffffff" align="center">
          <tr>
               <td style="padding: 5px 0px 5px 35px;cursor: pointer;">
	               <div style="float: left;"><img src="../images/an12.gif" width="106" height="31" id="addPaintingImage" ></div>
	               <div style="float: left;padding-left: 35px;"><input type="button" class="btn_4" name="paintings_painter" onclick="view_paintings_painter()" value="画作排序"/></div>
               </td>
         </tr>
         <tr>											
             <td>
				<table cellpadding="0" cellspacing="0" border="0">
					 <c:forEach items="${requestScope.paintingList}" var="result" varStatus="status">
			              <%@ include file="/member/painting_detail_fragment.jsp" %>
					</c:forEach>
				</table>
			</td>
		</tr>
	</table>
         
  
 </form>  

<jsp:include page="/commons/foot_member.jsp"></jsp:include>

</body>
</html>